﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DispatchAssist.Weather.Interfaces;
using Microsoft.Practices.Unity;
using Microsoft.Practices.Unity.Configuration;
using DispatchAssist.Weather.Providers;
using DispatchAssist.Weather.Entities;
using DispatchAssist.Weather.Implements;

namespace DispatchAssist.Weather.Helper
{
    class ProviderHelper
    {
        /// <summary>
        /// 探测中心
        /// </summary>
        public const string MOCProvider = "MOCProvider";
        /// <summary>
        /// 中央气象台
        /// </summary>
        public const string NMCProvider = "NMCProvider";
        /// <summary>
        /// 中国天气网
        /// </summary>
        public const string WeatherNetProvider = "WeatherNetProvider";

        /// <summary>
        /// 获取数据源
        /// </summary>
        /// <returns></returns>
        public static IWeatherDisplayProvider GetWeatherProvider()
        {
            IWeatherDisplayProvider provider = null;
            var mapProvider = WeatherDataHelper.WeatherData.GetMapProvider(Properties.UserSettings.Default.DefaultProvider);
            if (mapProvider == null)
                return provider;

            switch (mapProvider.ProviderID)
            {
                case MOCProvider:
                    provider = new MOCDisplayProvider(mapProvider);
                    break;
                case NMCProvider:
                    provider = new NMCDisplayProvider(mapProvider);
                    break;
                case WeatherNetProvider:
                    provider = new WeatherNetDisplayProvider(mapProvider);
                    break;
                default:
                    provider = new MOCDisplayProvider(mapProvider);
                    break;
            }

            return provider;
        }

        public static IList<IWeatherMapProvider> GetAllWeatherProvider()
        {
            return WeatherDataHelper.WeatherData.Providers;
        }

        private static Dictionary<Guid, IGetPics> dicPics = new Dictionary<Guid, IGetPics>();
        public static IGetPics GetWeatherMapInfo(IWeatherMapInfo mapInfo)
        {
            if (dicPics.ContainsKey(mapInfo.WeatherMapInfoID))
            {
                return dicPics[mapInfo.WeatherMapInfoID];
            }


            IGetPics pic = null;
            switch (mapInfo.WeatherMapType.MapType)
            {
                case Enums.MapTypes.MOCRadar:
                    pic = new MocCountrywideRadarWeatherMapInfo(mapInfo);
                    dicPics.Add(mapInfo.WeatherMapInfoID, pic);
                    break;
                case Enums.MapTypes.MOCCityRadar:
                    pic = new MocCityRadarWeatherMapInfo(mapInfo);
                    dicPics.Add(mapInfo.WeatherMapInfoID, pic);
                    break;
                case Enums.MapTypes.NMCRadar:
                    pic = new NmcCountrywideRadarWeatherMapInfo(mapInfo);
                    dicPics.Add(mapInfo.WeatherMapInfoID, pic);
                    break;
                case Enums.MapTypes.NMCCityRadar:
                    pic = new NmcCityRadarWeatherMapInfo(mapInfo);
                    dicPics.Add(mapInfo.WeatherMapInfoID, pic);
                    break;
                case Enums.MapTypes.WNRadar:
                    pic = new WNCountrywideRadarWeatherMapInfo(mapInfo);
                    dicPics.Add(mapInfo.WeatherMapInfoID, pic);
                    break;
                case Enums.MapTypes.WNCityRadar:
                    pic = new WNCityRadarWeatherMapInfo(mapInfo);
                    dicPics.Add(mapInfo.WeatherMapInfoID, pic);
                    break;
            }

            return pic;
        }



        public static IList<AnimateDisplayTime> GetAnimateDataSource()
        {
            return new List<AnimateDisplayTime> {
             new AnimateDisplayTime{ Text = "最新图片", AnimateTime=0},
             new AnimateDisplayTime{ Text = "最近0.5小时图片", AnimateTime=0.5},
             new AnimateDisplayTime{ Text = "最近1小时图片", AnimateTime=1},
             new AnimateDisplayTime{ Text = "最近1.5小时图片", AnimateTime=1.5},
             new AnimateDisplayTime{ Text = "最近2小时图片", AnimateTime=2},
            };
        }
    }
}
